package cn.hyatt.auth.utils;

import cn.hyatt.auth.security.entity.LoginUserDetails;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Security工具
 *
 * @author hyatt
 */
public class SecurityUtil {
    /**
     * 获取 身份验证
     * @return 结果
     */
    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    /**
     * 获取登录用户详细信息
     * @return 结果
     */
    public static LoginUserDetails getLoginUserDetails() {
        return (LoginUserDetails) getAuthentication().getPrincipal();
    }

    /**
     * 获取用户Id
     * @return 结果
     */
    public static Long getUserId() {
        return getLoginUserDetails().getId();
    }
}
